package com.jyhz.model.controller;

import com.jyhz.common.dto.HttpResult;
import com.jyhz.common.util.HttpStatusCode;
import com.jyhz.common.util.TimeUtils;
import com.jyhz.model.pojo.Person;
import com.jyhz.model.service.PersonService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:谢君臣
 * @Date:2021/6/27-19:25
 * @version:1.0
 * @function:
 */
@RestController
@Api("用户管理模块")
public class PersonController {

    @Autowired
    private PersonService personService;

    @GetMapping("/user/get")
    public HttpResult getUserByUsernameAndPassword(@Param("username") String username,
                                                   @Param("password") String password){
        Person person = personService.getOneByUsernameAndPassword(username,password);
        return new HttpResult(
                HttpStatusCode.OK.getCode(),
                HttpStatusCode.OK.getZhMessage(),
                person,
                TimeUtils.nowStr(TimeUtils.DEF_FMT_DATE_TIME)
        );
    }
    @GetMapping("/user/get/{UserId}")
    public HttpResult getOneUser(@PathVariable("UserId") Long UserId){
        Person person = personService.getOneById(UserId);
        return new HttpResult(
                HttpStatusCode.OK.getCode(),
                HttpStatusCode.OK.getZhMessage(),
                person,
                TimeUtils.nowStr(TimeUtils.DEF_FMT_DATE_TIME)
        );
    }

}
